package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TmcHouseInfo;
import com.ruoyi.system.domain.TmcHouseUser;
import com.ruoyi.system.service.TmcHouseUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
@RestController
@RequestMapping("/system/house")
public class TmcHouseUserController extends BaseController {
    @Autowired
    private TmcHouseUserService tmcHouseInfoService;

    /**
     * 查询房屋产权信息
     * 列表
     */
//    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TmcHouseInfo tmcHouseInfo) {
        startPage();
        List<TmcHouseInfo> list = tmcHouseInfoService.selectTmcHouseInfoList(tmcHouseInfo);
        return getDataTable(list);
    }
        @GetMapping("/User/list")
    public TableDataInfo Userlist(TmcHouseUser user) {
        startPage();
            List<TmcHouseUser> list = tmcHouseInfoService.selectTmcHouseUserList(user);
        return getDataTable(list);
    }

    /**
     * 获取房屋产权信息
     * 详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping("/update/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tmcHouseInfoService.selectTmcHouseInfoById(id));
    }

    /**
     * 新增房屋产权信息
     */
//@PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "房屋产权信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmcHouseInfo tmcHouseInfo) {
        return toAjax(tmcHouseInfoService.insertTmcHouseInfo(tmcHouseInfo));
    }

    /**
     * 修改房屋产权信息
     */
//        @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "房屋产权信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmcHouseInfo tmcHouseInfo) {
        return toAjax(tmcHouseInfoService.updateTmcHouseInfo(tmcHouseInfo));
    }

    /**
     * 删除房屋产权信息
     */
//        @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "房屋产权信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tmcHouseInfoService.deleteTmcHouseInfoByIds(ids));
    }

    @ApiOperation(value = "项目导入")
    @Log(title = "项目导入", businessType = BusinessType.INSERT)
    @PostMapping(value = "/upload")
    @CrossOrigin
    public AjaxResult Upload(MultipartFile file) {
        if (tmcHouseInfoService.importExcel(file) > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
    /**
     * 获取房屋所属人中间详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/User/{id}")
    public AjaxResult UsergetInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tmcHouseInfoService.selectTmcHouseUserById(id));
    }

    /**
     * 新增房屋所属人中间
     */
//    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "房屋所属人中间", businessType = BusinessType.INSERT)
    @PostMapping("/User/add")
    public AjaxResult Useradd(@RequestBody TmcHouseUser tmcHouseUser)
    {
        return toAjax(tmcHouseInfoService.insertTmcHouseUser(tmcHouseUser));
    }

    /**
     * 修改房屋所属人中间
     */
//    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "房屋所属人中间", businessType = BusinessType.UPDATE)
    @PutMapping("/User")
    public AjaxResult Useredit(@RequestBody TmcHouseUser tmcHouseUser)
    {
        return toAjax(tmcHouseInfoService.updateTmcHouseUser(tmcHouseUser));
    }

    /**
     * 删除房屋所属人中间
     */
//    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "房屋所属人中间", businessType = BusinessType.DELETE)
    @DeleteMapping("/User/{ids}")
    public AjaxResult Userremove(@PathVariable Long[] ids)
    {
        return toAjax(tmcHouseInfoService.deleteTmcHouseUserByIds(ids));
    }
}
